//
//  CRPicTableViewCell.m
//  NewAge
//
//  Created by dllo on 15/11/28.
//  Copyright © 2015年 ColorRevolution. All rights reserved.
//

#import "CRPicTableViewCell.h"
#import "CRNewsModel.h"
#import "CRSpecialNewsModel.h"

@implementation CRPicTableViewCell

#pragma mark - init

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCell];
    }
    return self;
}



#pragma mark - createCell

- (void)createCell {
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.replyCountLabel];
    [self.contentView addSubview:self.leftImageView];
    [self.contentView addSubview:self.centerImageView];
    [self.contentView addSubview:self.rightImageView];
    [self.contentView addSubview:self.lineView];
}


#pragma mark - lazyLoad

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        self.titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:15];
    }
    return _titleLabel;
}

- (UILabel *)replyCountLabel {
    if (!_replyCountLabel) {
        self.replyCountLabel = [[UILabel alloc] init];
        _replyCountLabel.font = [UIFont systemFontOfSize:14];
        _replyCountLabel.textColor = [UIColor colorWithRed:0.698f green:0.698f blue:0.698f alpha:1.00f];
        _replyCountLabel.textAlignment = NSTextAlignmentRight;
    }
    return _replyCountLabel;
}

- (UIImageView *)leftImageView {
    if (!_leftImageView) {
        self.leftImageView = [[UIImageView alloc] init];
    }
    return _leftImageView;
}

- (UIImageView *)centerImageView {
    if (!_centerImageView) {
        self.centerImageView = [[UIImageView alloc] init];
    }
    return _centerImageView;
}

- (UIImageView *)rightImageView {
    if (!_rightImageView) {
        self.rightImageView = [[UIImageView alloc] init];
    }
    return _rightImageView;
}

- (UIView *)lineView {
    if (!_lineView) {
        self.lineView = [[UIView alloc] init];
        _lineView.backgroundColor =  [UIColor colorWithRed:0.871f green:0.871f blue:0.871f alpha:0.50f];
    }
    return _lineView;
}



#pragma mark - SetterMethod

- (void)setNews:(CRNewsModel *)news {
    if (_news != news) {
        _news = news;
        
        [self changeValue];
    }
}

- (void)setSpecialNews:(CRSpecialNewsModel *)specialNews {
    if (_specialNews != specialNews) {
        _specialNews = specialNews;
        
        [self changeValue];
    }
}

- (void)changeValue {
    if (_news) {
        _titleLabel.text = _news.title;
        _replyCountLabel.text = [NSString stringWithFormat:@"%@跟帖", _news.replyCount];
        [_leftImageView sd_setImageWithURL:[NSURL URLWithString:_news.imgsrc] placeholderImage:nil];
        [_centerImageView sd_setImageWithURL:_news.imgextra[0][@"imgsrc"] placeholderImage:nil];
        [_rightImageView sd_setImageWithURL:_news.imgextra[1][@"imgsrc"] placeholderImage:nil];
    }
    else if (_specialNews) {
        _titleLabel.text = _specialNews.title;
        _replyCountLabel.text = [NSString stringWithFormat:@"%@跟帖", _specialNews.replyCount];
        [_leftImageView sd_setImageWithURL:[NSURL URLWithString:_specialNews.imgsrc] placeholderImage:nil];
        [_centerImageView sd_setImageWithURL:_specialNews.imgextra[0][@"imgsrc"] placeholderImage:nil];
        [_rightImageView sd_setImageWithURL:_specialNews.imgextra[1][@"imgsrc"] placeholderImage:nil];
    }
}



#pragma mark - setLayout

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        Top(self.contentView.mas_top, 12 * HEIGHT / 667.0);
        Left(self.contentView.mas_left, 5 * WIDTH / 375.0);
        WequalNum(300 * WIDTH / 375.0);
        HequalNum(18 * HEIGHT / 667.0);
        Bottom(_leftImageView.mas_top, -5 * HEIGHT / 667.0);
    }];
    
    [_replyCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        Top(self.contentView.mas_top, 12 * HEIGHT / 667.0);
        Right(self.contentView.mas_right, -5 * WIDTH / 375.0);
        WequalNum(70 * WIDTH / 375.0);
        HequalView(_titleLabel);
        Bottom(_leftImageView.mas_top, -5 * HEIGHT / 667.0);
    }];
    
    [_leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        Top(_titleLabel.mas_bottom, 5 * HEIGHT / 667.0);
        Left(self.contentView.mas_left, 5 * WIDTH / 375.0);
        Right(_centerImageView.mas_left, -5 * WIDTH / 375.0);
        Bottom(self.contentView.mas_bottom, -12 * HEIGHT / 667.0);
        WequalView(_centerImageView);
    }];
    
    [_centerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        Top(_titleLabel.mas_bottom, 5 * HEIGHT / 667.0);
        Left(_leftImageView.mas_right, 5 * WIDTH / 375.0);
        Right(_rightImageView.mas_left, -5 * WIDTH / 375.0);
        Bottom(self.contentView.mas_bottom, -12 * HEIGHT / 667.0);
        WequalView(_rightImageView);
    }];
    
    [_rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        Top(_titleLabel.mas_bottom, 5 * HEIGHT / 667.0);
        Left(_centerImageView.mas_right, 5 * WIDTH / 375.0);
        Right(self.contentView.mas_right, -5 * WIDTH / 375.0);
        Bottom(self.contentView.mas_bottom, -12 * HEIGHT / 667.0);
        WequalView(_leftImageView);
    }];
    
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        Left(self.contentView.mas_left, 0);
        Right(self.contentView.mas_right, 0);
        Bottom(self.contentView.mas_bottom, 0);
        HequalNum(0.5);
    }];
}

- (UIView *)linewView {
    if (!_lineView) {
        self.lineView = [[UIView alloc] init];
        _lineView.backgroundColor =  [UIColor colorWithRed:0.871f green:0.871f blue:0.871f alpha:0.50f];
    }
    return _lineView;
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
